<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ArticleDao
 *
 * @author Binh
 */
class UserDao {
    public static function getUser($email, $pass) {
        $user = NULL;
        $sql = sprintf("select * from user where deleted=0 and email='%s' and pass='%s'", $email, $pass);
        $helper = new MySqlDataAccessHelper;

        $helper->open();
        $rs = $helper->executeQuery($sql);
        if (FALSE === $rs) {
            echo mysql_error();
            return $ds;
        } else {
            if ($row = mysql_fetch_array($rs)) {
                $user = new User($row["id"],$row["name"],$row["email"],$row["pass"],$row["admin"]);
            }
            $helper->close();
            return $user;
        }
    }
    
    public static function insertUser($name, $email, $pass, $admin) {
        $sql = sprintf("INSERT INTO user (name, email, pass, admin) Values('%s', '%s', '%s', %d)", $name, $email, $pass, $admin);
        $helper = new MySqlDataAccessHelper;

        $helper->open();
        $msg = $helper->executeUpdate($sql);
        if($msg != NULL){
            return NULL;
        }
        $id = mysql_insert_id();
        $user = new User($id, $name, $email, $pass, $admin);
        $helper->close();
        return $user;
    }
}

?>
